package com.hao.crud.service;

import com.hao.crud.bean.Employee;
import com.hao.crud.bean.EmployeeExample;
import com.hao.crud.dao.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hao   email：huanghao.0508@qq.com
 * @ClassName：EmployeeService
 * @description ：TODO
 * @create 2020-10-28-15:16
 */
@Service("employeeService")
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    public List<Employee> getAll(){
      return  employeeMapper.selectByExampleWithDept(null);
    }

    public void save(Employee emp) {
        employeeMapper.insertSelective(emp);
    }
    /**
     * @param: empName 员工姓名
     * @description: 检查数据库中是否有该员工
     * @return: boolean
     * @author: hao
     * @date: 2020/10/30
     */
    public boolean checkUser(String empName) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count = employeeMapper.countByExample(example);
        return count==0;
    }
    /**
     * @param: empId
     * @description: TODO 根据员工id查询员工
     * @return: com.hao.crud.bean.Employee
     * @author: hao
     * @date: 2020/10/31
     */
    public Employee selectEmpById(Integer empId) {
        return employeeMapper.selectByPrimaryKey(empId);
    }

    /**
     * @param: emp
     * @description: TODO 修改指定员工的信息
     * @return: void
     * @author: hao
     * @date: 2020/10/31
     */
    public void updateEmp(Employee emp) {
        employeeMapper.updateByPrimaryKeySelective(emp);
    }

    public void deleteEmp(Integer empId) {
        employeeMapper.deleteByPrimaryKey(empId);
    }

    public void deleteEmpAll(List<Integer> ids) {
        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andDIdIn(ids);
        employeeMapper.deleteByExample(employeeExample);
    }
}
